package com.zhouyibike.uu.receiver;

import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

/**
 * Created by Zy on 2017/10/24.
 */
public class LanyaBR extends BroadcastReceiver {

    private BRInteraction brInteraction;
    @Override
    public void onReceive(Context context, Intent intent) {
        switch(intent.getAction()){
            case BluetoothAdapter.ACTION_STATE_CHANGED:
                int blueState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 0);
                switch(blueState){
                    case BluetoothAdapter.STATE_TURNING_ON:
                        Log.e("blueaa","onReceive---------STATE_TURNING_ON");
                        brInteraction.setText("正在开启");
                        break;
                    case BluetoothAdapter.STATE_ON:
                        Log.e("blueaa","onReceive---------STATE_ON");
                        brInteraction.setText("开启了");
                        break;
                    case BluetoothAdapter.STATE_TURNING_OFF:
                        Log.e("blueaa","onReceive---------STATE_TURNING_OFF");
                        brInteraction.setText("正在关闭");
                        break;
                    case BluetoothAdapter.STATE_OFF:
                        Log.e("blueaa","onReceive---------STATE_OFF");
                        brInteraction.setText("关闭了");
                        break;
                }
                break;
        }
//        Bundle bundle = intent.getExtras();
//        //获取当前电量
//        int current = bundle.getInt("level");
//        //获取总电量（电池的电池容量）
//        int total = bundle.getInt("scale");
//        brInteraction.setText("当前电量：" + current + ",总电量：" + total);
    }

    public interface BRInteraction {
        public void setText(String content);
    }

    public void setBRInteractionListener(BRInteraction brInteraction) {
        this.brInteraction = brInteraction;
    }
}
